package com.boodaba.todocarts.app;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.boodaba.todocarts.domain.ILabelRepository;
import com.boodaba.todocarts.domain.Label;
import com.google.inject.Inject;

public class LabelPresenter extends BasePresenter<ILabelActivity> {
	
	private ILabelRepository mLabelRepository;
	
	@Inject
	public LabelPresenter(ILabelRepository labelRepository) {
		mLabelRepository = labelRepository;
	}

	public void initializeWith(ILabelActivity labelActivity) {
		super.initializeWith(labelActivity);
		
		setTitleListInActivity();
	}

	public void startAddLabel() {
		getActivity().startAddLabel();
	}

	public void showLabelTodos() {
		getActivity().startLabelTodos(getActivity().getSelectedTitle());		
	}

	public void startEditLabel() {
		getActivity().startEditLabel(getActivity().getSelectedTitle());
	}

	public void returnTo() {
		setTitleListInActivity();		
	}
	
	private void setTitleListInActivity() {
		List<String> titleList = new ArrayList<String>();
		List<Label> labelList = mLabelRepository.findAll();
		for (Label label : labelList) {
			titleList.add(label.getTitle());
		}
		Collections.sort(titleList);
		getActivity().setLabelList(titleList);
	}

}
